package com.zgkj.Zip.tools;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class FileList {
  private File file;
  private List<File> fileList;
  private HashMap<String,Object> filesmap;//




  public HashMap<String, Object> getFilesmap() {
	return filesmap;
}

public void setFilesmap(HashMap<String, Object> filesmap) {
	this.filesmap = filesmap;
}

public FileList(File filepath) throws Exception{
    this.file=filepath;  //文件夹地址
    fileList = new ArrayList<>();
    filesmap = new HashMap<>();
    getList();
    getFileMap();
  }

  public void getList() throws Exception{
	  if(file.isDirectory()){
          File[] fileArray=file.listFiles();
          if(fileArray!=null){
              for (File element : fileArray) {
            	  file = element;
            	  getList();
              }
          }
      }else{
    	  fileList.add(file);
      }
  }

  public void getFileMap() throws Exception{
	 List tifList = new ArrayList<String>();
	 List pdfList = new ArrayList<String>();
	 for (File file : fileList) {
		 //System.out.println(file.getPath());
		 String filename = file.getName();
		 String filetype  =filename.substring(filename.lastIndexOf(".")+1,filename.length()).toUpperCase();
		 //System.out.println(filename);
		// System.out.println(filetype);
		 if(filetype.equals("TIF")){
			 System.out.println(java.net.URLDecoder.decode(file.getPath(),"utf-8"));
			 tifList.add(file.getPath());
		 }
		 if(filetype.equals("XML")){
			 if(filename.toUpperCase().equals("LIST.XML")){
				 //System.out.println(file.getPath());
				 filesmap.put("LISTXML", java.net.URLDecoder.decode(file.getPath(),"utf-8"));
			 }else if(filename.toUpperCase().startsWith("GA")){
				 //System.out.println(file.getPath());
				 filesmap.put("GAXML", java.net.URLDecoder.decode(file.getPath(),"utf-8"));
			 }
		 }
//		 System.out.println(filename.substring(0,filename.lastIndexOf(".")));
//		 System.out.println(filetype);
		 if(filetype.equals("PDF")&&!filename.substring(0,filename.lastIndexOf(".")).endsWith("ABC")){
			 pdfList.add( java.net.URLDecoder.decode(file.getPath(),"utf-8"));
		 }
	}
	 filesmap.put("TIFLIST", tifList);
	 filesmap.put("PDFLIST", pdfList);
  }

  public File getFile() {
	return file;
}

public void setFile(File file) {
	this.file = file;
}

public List<File> getFileList() {
	return fileList;
}

public void setFileList(List<File> fileList) {
	this.fileList = fileList;
}

public static void main(String[] args) throws Exception {
	  FileList FileList = new FileList(new File("D:\\550161910\\cpc案卷样式"));
}
}
